package com.example.threaddemo;

public class Demo2 {

    public static void main(String[] args) {
        MyData myData = new MyData();
        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    myData.addPlus();
                    myData.addMyAtomic();
                }
            }, "coco").start();
        }

        //守护线程和GC线程
        while (Thread.activeCount() > 2) {
            Thread.yield();
        }

        System.out.println(Thread.currentThread().getName() + " value:" + myData.number);
        System.out.println(Thread.currentThread().getName() + " value:" + myData.atomicInteger);
    }
}
